﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HynuIOTA.Entity.FormatEntity;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text;
using HynuIOTA.Web;

namespace System.Web.Mvc
{
    public class BaseController : Controller
    {
        /// <summary>
        /// 操作上下文
        /// </summary>
        public OperationContext OpContext
        {
            get
            {
                return OperationContext.Current;
            }
        }

        #region Json消息封装
        /// <summary>
        /// 返回 Ajax 消息 Json字符串
        /// </summary>
        /// <param name="status"></param>
        /// <param name="msg"></param>
        /// <param name="backurl"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult JsonMessage(AjaxMsgStatus status = AjaxMsgStatus.OK, string msg = "", string backurl = "", object data = null)
        {
            return OpContext.JsonMessage(status, msg, backurl, data);
        }

        /// <summary>
        /// Json返回OK
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="backurl"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult JsonMsgOK(string msg = "", string backurl = "", object data = null)
        {
            return OpContext.JsonMessage(AjaxMsgStatus.OK, msg, backurl, data);
        }

        /// <summary>
        /// Json返回失败
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="backurl"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult JsonMsgFail(string msg = "", string backurl = "", object data = null)
        {
            return OpContext.JsonMessage(AjaxMsgStatus.Fail, msg, backurl, data);
        }

        /// <summary>
        /// Json返回错误
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="backurl"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult JsonMsgErr(string msg = "", string backurl = "", object data = null)
        {
            return OpContext.JsonMessage(AjaxMsgStatus.Error, msg, backurl, data);
        }

        /// <summary>
        /// Json返回未登录
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="backurl"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult JsonMsgNoLogin(string msg = "", string backurl = "", object data = null)
        {
            return OpContext.JsonMessage(AjaxMsgStatus.NoLogin, msg, backurl, data);
        }

        /// <summary>
        /// Json返回没有权限
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="backurl"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ActionResult JsonMsgNoPer(string msg = "", string backurl = "", object data = null)
        {
            return OpContext.JsonMessage(AjaxMsgStatus.NoPer, msg, backurl, data);
        }


        /// <summary>
        /// Json消息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public new ContentResult Json(object data)
        {
            return OpContext.Json(data);
        }
        #endregion

        #region Js提示封装
        /// <summary>
        /// 返回 alert location js代码标签
        /// </summary>
        /// <param name="strMsg"></param>
        /// <param name="backUrl"></param>
        /// <returns></returns>
        public ContentResult JsMsg(string strMsg, string backUrl = "")
        {
            return OpContext.JsMsg(strMsg, backUrl);
        }
        #endregion
    }
}